/**
 * 
 */
package hu.gbalage.owl;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.semanticweb.owl.inference.OWLReasoner;
import org.semanticweb.owl.model.OWLOntologyManager;

/**
 * This class loads and initializes any registered owl reasoner
 * @author Grill Balazs (balage.g@gmail.com)
 *
 */
public class ConfiguredOWLReasoner {

	public static String EP_OWLREASONERFACTORY = "hu.gbalage.owl.reasonerfactories";
	
	public static String EPA_FACTORY = "factory";
	
	public static OWLReasoner createReasoner(OWLOntologyManager manager){
		IExtensionRegistry registry = Platform.getExtensionRegistry();  
		if (registry == null) return null;
		IExtensionPoint point = registry.getExtensionPoint(EP_OWLREASONERFACTORY);
		for (IExtension extension : point.getExtensions()){ 
			for (IConfigurationElement element : extension.getConfigurationElements()){
				try {
					Object o = element.createExecutableExtension(EPA_FACTORY);
					if (o instanceof IOWLReasonerFactory){
						return ((IOWLReasonerFactory)o).createReasoner(manager);
					}
				} catch (CoreException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}
	
}
